﻿using System;
using System.Windows.Data;
using System.Collections.Generic;
using System.Globalization;

namespace Common
{

    public class DataClass
    {
        public virtual void SetData(Tokenizer tokenizer) { }
    }

    public class Result
    {
        public bool result { get; set; }
        public string command { get; set; }
        public string error { get; set; }
        public string data { get; set; }

        public Result()
        {
        }
    }

    public class MenuItem : DataClass
    {
        public string id { get; set; }
        public string p_id { get; set; }
        public string menu_nm { get; set; }
        public string rw { get; set; }
        public string order_no { get; set; }
        public string uri { get; set; }

        public List<MenuItem> child = new List<MenuItem>();

        public MenuItem()
        {
            this.id = "";
            this.p_id = "";
            this.menu_nm = "";
            this.rw = "";
            this.order_no = "";
            this.uri = "";

        }

        public override void SetData(Tokenizer tokenizer)
        {
            char sep = (char)128;
            
            p_id = tokenizer.StrTok(sep);
            id = tokenizer.StrTok(sep);
            order_no = tokenizer.StrTok(sep);
            menu_nm = tokenizer.StrTok(sep);
            uri = tokenizer.StrTok(sep);
            tokenizer.StrTok(sep);
            rw = tokenizer.StrTok(sep);
        }
    }

    public class Row
    {
        private System.Collections.Generic.Dictionary<string, object> _data = new System.Collections.Generic.Dictionary<string, object>();
        public object this[string index]
        {
            get { return _data[index]; }
            set { _data[index] = value; }
        }
    }


    public class RowIndexConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Row row = value as Row;
            string index = parameter as string;
            return row[index];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

}
